package com.bfly.mall.advert.service.impl;

import com.bfly.core.base.service.BaseServiceImpl;
import com.bfly.mall.advert.dao.CouponRangeBindMapper;
import com.bfly.mall.advert.entity.CouponRangeBind;
import com.bfly.mall.advert.service.ICouponRangeBindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @author 长沙商脉科技有限公司
 * @date 2020/9/20 13:05
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS)
public class CouponRangeBindServiceImpl extends BaseServiceImpl<CouponRangeBind, Integer> implements ICouponRangeBindService {

    @Autowired
    private CouponRangeBindMapper couponRangeBindMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void save(int couponId, int rangeId) {
        CouponRangeBind cg = new CouponRangeBind();
        cg.setRangeId(rangeId);
        cg.setCouponId(couponId);
        cg.setCreateDate(new Date());
        cg.setUpdateDate(new Date());
        super.save(cg);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removeByCoupon(int couponId) {
        couponRangeBindMapper.removeByCoupon(couponId);
    }
}
